#!/bin/bash -e

function info() {
echo Usage: `basename $0` 'beta_test.txt site_num_max'
exit 1
}

while getopts  ":p:f:" opt; do
	case  $opt  in
		p) out_prefix=$OPTARG;;
		f) suffix=$OPTARG;;
		*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

. $var

ids=$data_path/meth/b450k.id.npy
nf_new=$2


cat $1|cut -f1 > $out_prefix.ids_test.txt

ids_sub450.py $ids $out_prefix.ids_test.txt $nf_new $out_prefix.nf_test.txt
dos2unix $out_prefix.nf_test.txt

# for tag in sub. '' can_merge. can_sub.merge.; do

for tag in .sub. '.'; do

    b450k_no_name=$data_path/meth/b450k${tag}no_name.txt
    names=$data_path/meth/b450k${tag}names.txt
    
    nf=`awk '{print NF; exit 0}' $b450k_no_name`
    echo $nf
    
    file_name=''
    j=0
    for nf in `cat $out_prefix.nf_test.txt`; do
        ((j+=1))
        cut -f $nf $b450k_no_name > $out_prefix.b450k.sub${tag}${j}.txt
        file_name="$file_name $out_prefix.b450k.sub${tag}${j}.txt"
    done
    
    echo $file_name
    paste $names $file_name > $out_prefix.train.random_site${tag}txt
    rm $file_name
    
    ln -sf $out_prefix.train.random_site${tag}txt $out_prefix.b450k.sub.test${tag}txt

done

. $cmd_done